<#import "../common/layout.ftl" as layout/>
<#import "../common/dataTables.ftl" as dataTables/>
<#import "../common/modern-forms.ftl" as mform/>
<#import "../common/modal.ftl" as modal/>


<!DOCTYPE html>
<html>
<@layout.head title="资产使用变动">
    <@dataTables.head/>
    <@dataTables.buttons_head/>
    <@dataTables.select_head/>
    <@dataTables.fixedHeader_head/>
    <@mform.head/>
    <@select.head/>
<style>
    .showImagBox {
        text-align: center;
    }

    .showImagBox img {
        height: 100%;
    }
</style>
</@layout.head>
<body>
<@layout.page>
<div class="main-box">
    <div class="content">
        <div style="position: relative;top:50px;">
            <div>
                <div style="position: absolute;top: 0px">
                    <select id='changeTypes' name='changeTypes' style="width: 150px">
                        <option value="0">全部变动类型</option>
                        <#list echangeType as item>
                            <option value="${item.code}">${item.name}</option>
                        </#list>
                    </select>

                    <select id='states' name='states' style="width: 120px">
                        <option value="334001">未生效</option>
                        <option value="334002">已生效</option>
                        <option value="334003">驳回/作废</option>
                    </select>

                    <span>新增时间</span>
                    <input id="startdate" name="startdate" style="width: 100px" placeholder='请选择开始日期'/>
                    <span>至</span>
                    <input id="enddate" name="enddate" style="width: 100px" placeholder='请选择结束日期'/>

                    <button id="btnAddTopMenu" type="button" class="btn btn-blue btn-sm" style="margin-left: 5px;"
                            onclick="javascript:refreshData();">
                        <i class="fa fa-search"></i> 查询
                    </button>
                    <button id="btnAddTopMenu" type="button" class="btn btn-blue btn-sm" style="margin-left: 5px;"
                            onclick="javascript:newdetail();">
                        <i class="fa fa-plus"></i> 新增
                    </button>
                    <button id="btnAddTopMenu" type="button" class="btn btn-blue btn-sm" style="margin-left: 5px;"
                            onclick="javascript:editdetail();">
                        <i class="fa fa-edit"></i> 修改
                    </button>
                    <button id="btnAddTopMenu" type="button" class="btn btn-blue btn-sm" style="margin-left: 5px;"
                            onclick="javascript:checkdetail();">
                        <i class="fa fa-check"></i> 审核生效性
                    </button>
                    <button id="btnAddTopMenu" type="button" class="btn btn-blue btn-sm" style="margin-left: 5px;"
                            onclick="javascript:deldetail();">
                        <i class="fa fa-minus"></i> 删除
                    </button>
                </div>
            </div>
            <@dataTables.commonTable id="mainTable"/>
        </div>
        <div id="searchGroup" class="btn-group"
             style="position: absolute;top:10px;display: flex;width:calc(100% - 15px);">

            <div style="flex:3;" id="orgBox">

            </div>

            <div style="flex:1; display: flex">
                <select class='form-control' id='useStaffIds'
                        style='float:left; flex: 1;min-width: 150px'>
                    <option value="0">请选择使用人</option>
                    <#list staffList as item>
                        <option value="${item.id?c}">${item.name}</option>
                    </#list>
                </select>

                <select class='form-control' id='useTypes'
                        style='float:left; flex: 1;min-width: 150px'>
                    <option value="0">选择使用方式</option>
                    <#list useType as item>
                        <option value="${item.code}">${item.name}</option>
                    </#list>
                </select>
                <select class='form-control' id='brands'
                        style='float:left; flex: 1;min-width: 100px'>
                    <option value="0">选择品牌</option>
                    <#list brand as item>
                        <option value="${item.code}">${item.name}</option>
                    </#list>
                </select>
            </div>

            <div style="flex:1;">
                <select class='form-control' id='types1' placeholder='请选择一级分类'
                        style='width:100%;' onchange="typesChange()">
                    <option value='0'>请选择一级分类-0</option>
                    <#list eqRootClass as item>
                        <option value="${item.id?c}">${item.name}-${item.code}</option>
                    </#list>
                </select>
            </div>
            <div style="flex:1;" id='types2Box'>
            </div>
            <div>
                <input id="name" name="name" placeholder='型号名称/编码/二维码'
                       style=" flex: 1"/>
            </div>

        </div>
    </div>

    <!-- 弹出窗 -->
    <@modal.editModal id="modal-detail" buttonId="btndetailSave" width="1300px" height="100px">
        <@mform.container  id="editForm" width="450px">
            <input id="id" name="id" type="hidden"/>
            <input id="oldOrg" name="oldOrg" type="hidden"/>
            <input id="oldPosition" name="oldPosition" type="hidden"/>
            <input id="oldStaff" name="oldStaff" type="hidden"/>
            <input id="oldUseType" name="oldUseType" type="hidden"/>
            <div style="background-color: #efefef;">
                <@mform.select2 id='QRCode' name='QRCode' label="查询二维码加载当前设备信息"  size=12 onchange="QRCodeChange()">
                    <option value="">查询二维码</option>
                    <#list QRcode as item>
                        <option value="${item.id?c}">${item.code}</option>
                    </#list>
                </@mform.select2>
                <@mform.input_text id='organizationId' name='organizationId' size=12 label='使用机构'  placeholder='无'   readonly="true" icon='fa-lock'/>
                <@mform.input_text id='usePosition' name='usePosition' size=12 label='使用位置'  placeholder='无'   readonly="true" icon='fa-lock'/>
                <@mform.row>
                    <@mform.input_text id='useStaffId' name='useStaffId' size=6 label='使用人' placeholder='无'   readonly="true" icon='fa-lock' />
                    <@mform.input_text id='useType' name='useType' size=6 label='使用方式' placeholder='无'  readonly="true" icon='fa-lock' />
                </@mform.row>
                <@mform.row>
                    <@mform.input_text id='buyTime' name='buyTime' size=6 label='领用时间' placeholder='无'   readonly="true" icon='fa-lock' />
                    <@mform.input_text id='secrecy' name='secrecy' size=6 label='密保级别' placeholder='无'  readonly="true" icon='fa-lock' />
                </@mform.row>
                <@mform.row>
                    <@mform.input_text id='oneCode' name='oneCode' size=6 label='资产类型' placeholder='无'   readonly="true" icon='fa-lock' />
                    <@mform.input_text id='brandCode' name='brandCode' size=6 label='品牌' placeholder='无'  readonly="true" icon='fa-lock' />
                </@mform.row>
                <@mform.input_text id='modelId' name='modelId' size=12 label='型号名称' placeholder='无'   readonly="true" icon='fa-lock' />
                <@mform.row>
                    <@mform.input_text id='barCode' name='barCode' size=6 label='资产条形码' placeholder='无'   readonly="true" icon='fa-lock' />
                    <@mform.input_text id='state' name='state' size=6 label='当前状态' placeholder='无'  readonly="true" icon='fa-lock' />
                </@mform.row>
                <@mform.row>
                    <@mform.input_text id='warehouseId' name='warehouseId' size=6 label='仓库来源' placeholder='无'  readonly="true" icon='fa-lock' />
                    <@mform.input_text id='changeCode' name='changeCode' size=6 label='出库单' placeholder='无'  readonly="true" icon='fa-lock' />
                </@mform.row>
            </div>
            <div id="shade" style="background-color: rgba(0,0,0,0.3);height: 40px;
    width: 440px;
    position: absolute;
    left: 20px;
    top: 0px;
    color: #ffff00;
    padding: 10px;
    text-align: right;"> 此变动记录不允许重新选择设备
            </div>
        </@mform.container>
        <@mform.container id="editForm2" width="780px" >
            <div class="showImagBox" style="height: 153px; margin-bottom:20px; display: flex">
                <img src="" class="showImag" id="show" style="max-height: 100%; max-width: 40%;">
                <img src="" class="showImag" id="show2" style="max-height: 100%; max-width: 40%;margin-left:20px;">
            </div>
            <input id="fId" name="fId" type="hidden"/>
            <input id="id" name="id" type="hidden"/>
            <input id="eId" name="eId" type="hidden"/>
            <@mform.row>
                <@mform.select2 id='type' name='_type' label="变化方式"  size=6 onchange="eChangeTypeChange()">
                    <#list echangeType as item>
                        <option value="${item.code}">${item.name}</option>
                    </#list>
                </@mform.select2>

            <#--<@mform.select2 id='state' name='state' label="生效状态"  size=6 >-->
            <#--<#list state as item>-->
            <#--<option value="${item.code}">${item.name}</option>-->
            <#--</#list>-->
            <#--</@mform.select2>-->
            </@mform.row>
            <div id="warehouseBox">
                <@mform.row>
                    <@mform.select2 id='warehouseId' name='_warehouseId' label="选择仓库"  size=12>
                        <#list warehouseList as item>
                            <option value="${item.id?c}">${item.name}</option>
                        </#list>
                    </@mform.select2>
                </@mform.row>
            </div>
            <div id="userBox">
                <@mform.row>
                    <@mform.input_text id='oldOrg' name='oldOrg' size=6 label='原所属机构' icon='fa-lock' placeholder="未设置"  readonly="true"/>
                    <@mform.select2 id='newOrg' name='_newOrg' label="新所属机构"  size=6>
                    </@mform.select2>
                </@mform.row>
                <@mform.row>
                    <@mform.input_text id='oldStaff' name='oldStaff' size=6 label='原使用人' icon='fa-lock' placeholder="未设置"  readonly="true"/>
                    <@mform.select2 id='newStaff' name='_newStaff' label="新使用人"  size=6>
                        <#list staffList as item>
                            <option value="${item.id?c}">${item.name}</option>
                        </#list>
                    </@mform.select2>
                </@mform.row>
                <@mform.row>
                    <@mform.input_text id='oldUseType' name='oldUseType' size=6 label='原使用方式' icon='fa-lock' placeholder="未设置"  readonly="true"/>
                    <@mform.select2 id='newUseType' name='_newUseType' label="新使用方式"  size=6>
                        <#list useType as item>
                            <option value="${item.code}">${item.name}</option>
                        </#list>
                    </@mform.select2>
                </@mform.row>
                <@mform.row>
                    <@mform.input_text id='oldPosition' name='oldPosition' size=6 label='原使用位置' icon='fa-lock' placeholder="未设置"  readonly="true"/>
                    <@mform.input_text id='newPosition' name='newPosition' size=6 label='新使用位置' icon='fa-edit' placeholder="请输入"  />
                </@mform.row>
            </div>
        </@mform.container>

    </@modal.editModal>

    <!-- 驳回意见 弹出窗 -->
    <@modal.editModal id="modal-detail2" title="审核生效性" buttonId="btndetailSave2" width="500px">
        <@mform.container id="editForm3">
            <input id="id" name="id" type="hidden"/>
            <@mform.row>
                <@mform.select2 id='stateCheck' name='state' label="生效审核"  size=6  onchange="checkStateChange()">
                    <option value="334002">生效</option>
                    <option value="334003">驳回/作废</option>
                </@mform.select2>
                <@mform.input_textarea id="reason" name="reason" size=12 label="原因" placeholder="请输入原因"/>
            </@mform.row>
        </@mform.container>
    </@modal.editModal>
</@layout.page>
<@layout.foot>
    <@dataTables.foot/>
    <@dataTables.buttons_foot/>
    <@dataTables.select_foot/>
    <@dataTables.fixedHeader_foot/>
    <@mform.foot/>

    <script src="${request.contextPath}/assets/js/jquery.serializejson.min.js?v=3653060703"></script>
    <script type="text/javascript">
        var now = new Date();
        var begin = now.getFullYear() + "-" + (now.getMonth() + 1) + "-1";
        var endD;
        var nextMonth = now.getMonth() + 1;
        var nextMonthFirstDay = new Date(now.getFullYear(), nextMonth, 1);
        var oneDay = 1000 * 60 * 60 * 24;
        endD = new Date(nextMonthFirstDay - oneDay);
        var end = endD.getFullYear() + "-" + (endD.getMonth() + 1) + "-" + endD.getDate();
        $("#startdate").datetimepicker({
            language: "zh-CN",
            startView: 2,
            minView: 2,
            format: "yyyy-mm-dd",
            autoclose: true,
            initialDate: new Date(),
            todayBtn: true
        });
        $("#startdate").val(begin);
        $("#enddate").datetimepicker({
            language: "zh-CN",
            startView: 2,
            minView: 2,
            format: "yyyy-mm-dd",
            autoclose: true,
            todayBtn: true
        });
        $("#enddate").val(end);

        var orgInfo =${organizationName};
        var orgList = [];
        var orgSelect = $("<select id='oneOrganization' style='width:100%;'><option value='0'>请选择机构</option></select>");
        $("#orgBox").append(orgSelect);
        putOptions(orgSelect, "", orgInfo.list);
        putOptions($("#newOrg"), "", orgInfo.list);

        function putOptions(orgSelect, supername, list) {
            if (supername != "") supername = supername + "-";
            for (var i = 0; i < list.length; i++) {
                orgSelect.append("<option value=" + list[i].id + ">" + supername + list[i].name + "</option>")
                if (list[i].childrenOrg.length > 0) {
                    putOptions(orgSelect, supername + list[i].name, list[i].childrenOrg);
                }
            }
        }

        orgSelect.select2();

        function putList(orgList, supername, list) {
            if (supername != "") supername = supername + "-";
            for (var i = 0; i < list.length; i++) {
                orgList.push({
                    id: list[i].id,
                    name: list[i].name
                })
                if (list[i].childrenOrg.length > 0) {
                    putList(orgList, supername + list[i].name, list[i].childrenOrg);
                }
            }
        }

        putList(orgList, "", orgInfo.list);

        function getOrgName(id) {
            for (var i = 0; i < orgList.length; i++) {
                if (orgList[i].id == id) return orgList[i].name
            }
        }

        function getType() {
            var types1 = $("#types1").find("option:selected").text().split("-")[1];
            var types2 = $("#types2").val();
            if (types2 == null || types2 == 0)
                return types1;
            else return types2;
        }

        function typesChange() {
            $.ajax({
                type: 'POST',
                data: {
                    datas: JSON.stringify({
                        superId: $("#types1").val()
                    })
                },
                url: "${request.contextPath}/base/eqClass/queryList",
                success: function (data) {
                    var data = data.datas;
                    //成功之后
                    var box = $("#types2Box");
                    box.html("");
                    if (data.length > 0 && $("#types1").val() != 0) {
                        //动态加载下拉框
                        var select = $("<select class='form-control' id='types2')> <option value=0>选择二级分类</option> </select>");
                        for (var i = 0; i < data.length; i++) {
                            select.append("<option value='" + data[i].code + "'>" + data[i].name + "</option>");
                        }
                        box.append(select);
                        select.select2();
                    }
                },
                error: function (xhr, type) {
                    swal("错误", "系统发生内部错误!请稍后再试!", "error");
                }
            });
        }

        var now = new Date();
        $("#buyTime").datetimepicker({
            language: "zh-CN",
            startView: 2,
            minView: 2,
            format: "yyyy-mm-dd",
            autoclose: true,
            initialDate: new Date(),
            todayBtn: true
        });
        var changeTypeList = {
            <#list changeType as item>
                "${item.code}": "${item.name}",
            </#list>}
        var echangeTypeList = {
            <#list echangeType as item>
                "${item.code}": "${item.name}",
            </#list>}
        var warehouseList = {
            <#list warehouseList as item>
                "${item.id?c}": "${item.name}",
            </#list>}
        var staffTypeList = {
            <#list staffType as item>
                "${item.code}": "${item.name}",
            </#list>}
        var useTypeList = {
            <#list useType as item>
                "${item.code}": "${item.name}",
            </#list>}
        var roleList = {
            <#list staffRole as item>
                "${item.cRoleID}": "${item.cRoleName}",
            </#list>}
        var eState = {
            <#list eState as item>
                "${item.code}": "${item.name}",
            </#list>}
        var state = {
            <#list state as item>
                "${item.code}": "${item.name}",
            </#list>}
        var secrecy = {
            <#list secrecy as item>
                "${item.code}": "${item.name}",
            </#list>}
        var staffList = {
            <#list staffList as item>
                "${item.id?c}": {
                    name: "${item.name}",
                    organizationId: "${item.organizationId?c}",
                    role: "${item.role}",
                    staffType: "${item.staffType}"
                },
            </#list>}
        var staffInfo;

        var mainTable = $('#mainTable').winningTable({
            columns: [
                {"sWidth": "150px", "title": "机构名称", "data": "organizationId"},
                {"sWidth": "150px", "title": "资产名称", "data": "name"},
                {"sWidth": "120px", "title": "资产条形码", "data": "barCode"},
                {"sWidth": "120px", "title": "二维码", "data": "QrCode"},
                {"sWidth": "80px", "title": "领用时间", "data": "buyTime"},
                {"sWidth": "80px", "title": "使用方式", "data": "useType"},

                {"sWidth": "100px", "title": "移交类型", "data": "type"},
                {"sWidth": "80px", "title": "新使用方式", "data": "newUseType"},
                {"sWidth": "150px", "title": "新机构", "data": "newOrg"},
                {"sWidth": "80px", "title": "新使用人", "data": "newStaff"},
                {"sWidth": "80px", "title": "新位置", "data": "newPosition"},
                {"sWidth": "80px", "title": "暂存仓库", "data": "warehouseId"},
                {"sWidth": "80px", "title": "变动状态", "data": "state"},
                {"sWidth": "80px", "title": "创建时间", "data": "createTime"}

            ],
            pageLenth: 40,
            searching: true,
            ordering: false,
            "order": [4, "desc"],
            dom: 'Bfrtip',
            buttons: [
                'excel', 'print'
            ],
            "rowCallback": function (row, data, index) {
                data.buyTime = data.buyTime.substr(0, 10)
                if (data.buyTime == null) data.buyTime = ""
                $('td', row).eq(4).html(data.buyTime);
                data._organizationId = data.organizationId;
                data.organizationId = getOrgName(data.oldOrg || data.organizationId);
                if (data.organizationId == null) data.organizationId = ""
                $('td', row).eq(0).html(data.organizationId);
                data._useType = data.useType;
                data.useType = useTypeList[data.oldUseType || data.useType]
                if (data.useType == null) data.useType = ""
                $('td', row).eq(5).html(data.useType);
                data._type = data.type;
                data.type = echangeTypeList[data.type]
                if (data.type == null) data.type = ""
                $('td', row).eq(6).html(data.type);
                data._newUseType = data.newUseType;
                data.newUseType = useTypeList[data.newUseType]
                if (data.newUseType == null) data.newUseType = ""
                $('td', row).eq(7).html(data.newUseType);
                data._newOrg = data.newOrg;
                data.newOrg = getOrgName(data.newOrg)
                if (data.newOrg == null) data.newOrg = ""
                $('td', row).eq(8).html(data.newOrg);
                if (staffList[data.newStaff] != null) {
                    data._newStaff = data.newStaff;
                    data.newStaff = staffList[data.newStaff]["name"]
                    if (data.newStaff == null) data.newStaff = ""
                    $('td', row).eq(9).html(data.newStaff);
                }
                data._warehouseId = data.warehouseId;
                data.warehouseId = warehouseList[data.warehouseId]
                if (data.warehouseId == null) data.warehouseId = ""
                $('td', row).eq(11).html(data.warehouseId);
                data._state = data.state;
                data.state = state[data.state]
                if (data.state == null) data.state = ""
                $('td', row).eq(12).html(data.state);
            }
        });

        function refreshData() {
            mainTable.queryData("${request.contextPath}/busi/equipment/useChange/queryEList", {
                datas: JSON.stringify({
                    changeType: $("#changeTypes").val(),
                    state: $("#states").val(),
                    b_createTime: $("#begindate").val(),
                    e_createTime: $("#enddate").val(),
                    oneOrganization: $("#oneOrganization").val(),
                    useStaffId: $("#useStaffIds").val(),
                    useType: $("#useTypes").val(),
                    brand: $("#brands").val(),
                    type: getType(),
                    name: $("#name").val(),
                })
            });
        }

        refreshData();

        function newdetail() {
            $('#modal-detail').find(".modal-title").text('新增');
            clearForm($('#modal-detail'));
            $("#show").attr("src", "");
            $("#show2").attr("src", "");
            eChangeTypeChange();
            $("#shade").hide();
            $("#btndetailSave").html("保存");
            $("#btndetailSave").unbind();
            $("#btndetailSave").click(savedetail);
            $('#modal-detail').modal();
        }

        $(".showImag").on("click", function (e) {
            if ($(e.target).attr("src") != null && $(e.target).attr("src") != "") {
                var big = $("<div style='position: absolute;top:0px;left:0px;width: 100%;height: 100%;background-color: rgba(0,0,0,0.5); text-align: center;z-index: 9999;'><img style='margin-top:20px;max-width: 80%;max-height:80%;' src='" + $(e.target).attr("src") + "'/></div>")
                $("body").append(big);
                big.on("click", function () {
                    big.children().remove();
                    big.remove();
                })
            }

        })
        $("#brandCode").bind("change", loadModel);
        $("#oneCode").bind("change", loadModel);

        function loadModel(initValue) {
            $.ajax({
                type: 'POST',
                data: {
                    datas: JSON.stringify({
                        oneCode: $("#oneCode").val(),
                        brandCode: $("#brandCode").val()
                    })
                },
                url: '${request.contextPath}/busi/equipment/use/queryModel',
                success: function (data) {
                    //成功之后
                    $("#modelId").children().remove();
                    var optionDefault = $("<option value='0'>请选择</option>");
                    $("#modelId").append(optionDefault);
                    if (data.success) {
                        $(data.datas).each(function (index, item) {
                            var option = $("<option value='" + item.id + "'>" + item.name + "-" + item.code + "</option>");
                            $("#modelId").append(option);
                        })
                        $("#modelId").val(initValue);
                        $('#select2-model-container').html($("#modelId").find("option:selected").text());
                    }
                    else {
                        swal("错误", data.errorMsg, "error");
                    }
                },
                error: function (xhr, type) {
                    swal("错误", "系统发生内部错误!请稍后再试!", "error");
                }
            })
        }


        function editdetail() {
            var datas = mainTable.getSelectedDatas();
            if (datas == null || datas.length == 0 || datas.length > 1) {
                swal("错误", "请选择一行数据", "error");
                return;
            }
            var $modal = $("#modal-detail");
            $modal.find(".modal-title").text("修改信息");
            clearForm($modal);
            var data = datas[0];
            initFormItemData($("#editForm2"), data);
            $("#modal-detail #select2-QRCode-container").html(data.QrCode);
            $("#editForm2 #oldOrg").val(getOrgName(data.oldOrg));
            $("#editForm2 #oldStaff").val(staffList[data.oldStaff]["name"]);
            $("#editForm2 #oldUseType").val(useTypeList[data.oldUseType]);
            $("#editForm2 #oldPosition").val(data.oldPosition);
            if ("124001,124002".indexOf(data.source) > -1)
                $("#shade").show();
            else
                $("#shade").hide();
            QRCodeChange();
            $modal.modal();
            eChangeTypeChange();
            $("#btndetailSave").unbind();
            $("#btndetailSave").click(savedetail);
        }


        function savedetail() {
            swal({
                title: "确定保存",
                text: "是否确定保存此数据",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "是的,确定",
                cancelButtonText: "取消"
            }).then(function (result) {
                if (!result.value)
                    return;
                var formData = $("#editForm2 form").serializeJSON();
                var form1Data = $("#editForm form").serializeJSON();
                var requestData={};
                requestData.id=formData.id;
                requestData.type=formData._type;
                requestData.warehouseId=formData._warehouseId;
                requestData.newOrg=formData._newOrg;
                requestData.newStaff=formData._newStaff;
                requestData.newUseType=formData._newUseType;
                requestData.newPosition=formData.newPosition;
                if(formData.id==""){
                    //新增，录入相关数据
                    requestData.eId=form1Data.id;
                    requestData.oldOrg=form1Data.oldOrg;
                    requestData.oldStaff=form1Data.oldStaff;
                    requestData.oldUseType=form1Data.oldUseType;
                    requestData.oldPosition=form1Data.oldPosition;
                    requestData.source="124003";
                }
                var params = {datas: JSON.stringify(requestData)};
                $.ajax({
                    type: 'POST',
                    data: params,
                    url: '${request.contextPath}/busi/equipment/useChange/saveEChange',
                    success: function (data) {
                        //成功之后
                        if (data.success) {
                            swal({
                                title: "成功",
                                text: "操作成功!",
                                type: "success",
                                showCancelButton: false,
                                confirmButtonText: "确定"
                            }).then(function (result) {
                                $("#modal-detail").modal('hide');
                                refreshData();
                            });
                        } else {
                            swal("错误", data.errorMsg, "error");
                        }
                    },
                    error: function (xhr, type) {
                        swal("错误", "系统发生内部错误!请稍后再试!", "error");
                    }
                });
            });
        }

        function deldetail() {
            var datas = mainTable.getSelectedDatas();
            if (datas == null || datas.length == 0) {
                swal("错误", "请选择数据", "error");
                return;
            }
            var ids = "";
            for (var i = 0; i < datas.length; i++) {
                ids += ("," + datas[i].id);
            }
            ids = ids.substr(1);
            swal({
                title: "确定删除",
                text: "是否确定删除此数据",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "是的,确定",
                cancelButtonText: "取消"
            }).then(function (result) {
                if (!result.value)
                    return;
                var requestData = {
                    id: ids
                };
                var params = {datas: JSON.stringify(requestData)};
                $.ajax({
                    type: 'POST',
                    data: params,
                    url: '${request.contextPath}/busi/equipment/useChange/delete',
                    success: function (data) {
                        //成功之后
                        if (data.success) {
                            swal({
                                title: "成功",
                                text: "操作成功!",
                                type: "success",
                                showCancelButton: false,
                                confirmButtonText: "确定"
                            }).then(function (result) {
                                refreshData();
                            });
                        } else {
                            swal("错误", data.errorMsg, "error");
                        }
                    },
                    error: function (xhr, type) {
                        swal("错误", "系统发生内部错误!请稍后再试!", "error");
                    }
                });
            });
        }

        //审核
        function checkdetail() {
            var datas = mainTable.getSelectedDatas();
            if (datas == null || datas.length == 0 || datas.length > 1) {
                swal("错误", "请选择一行申请数据", "error");
                return;
            }
            if (datas[0].state != "未生效") {
                swal("错误", "审核生效性后禁止此操作", "error");
                return;
            }
            var $modal = $("#modal-detail2");
            clearForm($modal);
            var data = datas[0];
            initFormItemData($("#editForm3"), data);
            $("#btndetailSave2").unbind();
            $("#btndetailSave2").click(saveCheck);
            $modal.modal();
        }

        // 保存审核
        function saveCheck() {
            swal({
                title: "确定保存",
                text: "是否确定保存此数据",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "是的,确定",
                cancelButtonText: "取消"
            }).then(function (result) {
                if (!result.value)
                    return;
                var requestData = $("#modal-detail2 form").serializeJSON();
                var params = {datas: JSON.stringify(requestData)};
                $.ajax({
                    type: 'POST',
                    data: params,
                    url: '${request.contextPath}/busi/equipment/useChange/checkEChange',
                    success: function (data) {
                        //成功之后
                        if (data.success) {
                            swal({
                                title: "成功",
                                text: "操作成功!",
                                type: "success",
                                showCancelButton: false,
                                confirmButtonText: "确定"
                            }).then(function (result) {
                                $("#modal-detail2").modal('hide');
                                refreshData();
                            });
                        } else {
                            swal("错误", data.errorMsg, "error");
                        }
                    },
                    error: function (xhr, type) {
                        swal("错误", "系统发生内部错误!请稍后再试!", "error");
                    }
                });
            });
        }

        checkStateChange();

        function checkStateChange() {
            var state = $("#stateCheck").val();
            if (state == '334003') {
                $("#reason").parents(".col").show();
            } else {
                $("#reason").parents(".col").hide();
            }
        }

        function eChangeTypeChange() {
            var type = $("#editForm2 #type").val();
            if ("123004,123005".indexOf(type) >= 0) {
                $("#editForm2 #warehouseBox").show();
                $("#editForm2 #userBox").hide();
            } else {
                $("#editForm2 #warehouseBox").hide();
                $("#editForm2 #userBox").show();
            }
        }

        function QRCodeChange() {
            var code = $("#select2-QRCode-container").html();
            $.ajax({
                type: 'POST',
                data: {
                    datas: JSON.stringify(
                            {
                                applyEquipment: code
                            }
                    )
                },
                url: '${request.contextPath}/busi/equipment/manage/queryEquipment',
                success: function (data) {
                    //成功之后
                    if (data.success) {
                        var entity = data.datas[0];
                        showNowInfo(entity);
                    } else {
                        swal("错误", data.errorMsg, "error");
                    }
                },
                error: function (xhr, type) {
                    swal("错误", "系统发生内部错误!请稍后再试!", "error");
                }
            });
        }

        function showNowInfo(data) {
            $("#show").attr("src", data.externalPhotos);
            $("#show2").attr("src", data.nameplatePhoto);
            $("#editForm #id").val(data.id);
            $("#editForm #oldOrg").val(data.organizationId);
            $("#editForm #oldStaff").val(data.staffId);
            $("#editForm #oldUseType").val(data.useType);
            $("#editForm #oldPosition").val(data.usePosition);
            $("#editForm #organizationId").val(getOrgName(data.organizationId));
            $("#editForm #usePosition").val(data.usePosition);
            $("#editForm #useStaffId").val(staffList[data.staffId]["name"]);
            $("#editForm #useType").val(useTypeList[data.useType]);
            $("#editForm #buyTime").val(data.buyTime.substr(0, 10));
            $("#editForm #secrecy").val(secrecy[data.secrecy]);
            $("#editForm #oneCode").val(data.type);
            $("#editForm #brandCode").val(data.brand);
            $("#editForm #modelId").val(data.modelName);
            $("#editForm #barCode").val(data.barCode);
            $("#editForm #state").val(eState[data.state]);
            $("#editForm #warehouseId").val(warehouseList[data.warehouseId]);
            $("#editForm #changeCode").val(data.changeCode);
        }
    </script>
</@layout.foot>
</body>
</html>